package com.bizfx.component.fields
{
	import com.bizfx.component.views.IDetailView;
	import com.bizfx.utils.StringUtils;
	
	import mx.collections.IList;
	import mx.controls.RadioButton;
	import mx.controls.RadioButtonGroup;
	import mx.core.IFlexDisplayObject;
	import mx.core.mx_internal;
	import mx.events.FlexEvent;
	import mx.utils.UIDUtil;
	
	use namespace mx_internal;

	[Event(name="dataChange", type="mx.events.FlexEvent")]
	
	public class RadioButtonGroupField extends RadioButtonGroup implements IField
	{		
		public function RadioButtonGroupField(document:IFlexDisplayObject = null){
			super(document);
		}

		private var _field_id:String;
		
		public function get id():String
		{
			return _field_id;
		}
		
		public function set id(value:String):void {
			this._field_id = value;
		}
		
		public function get fieldKey():String
		{
			return _field_id;
		}
		
		public function set fieldKey(value:String):void {
			this._field_id = value;
		}
		
		[Bindable("dataChange")]
		public function get data():Object {
			return this.selectedValue;
		}
		
		public function set data(value:Object):void {
			if (value == null) {
				this.selection = null;
			} else {
				this.selectedValue = value;
			}

			this.dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE, true));
		}
		
		private var _bindProperty:String;
		[Bindable]
		public function get bindProperty():String
		{
			return this._bindProperty;
		}
		
		public function set bindProperty(value:String):void
		{
			this._bindProperty = value;
		}
			
//		private var _view:IDetailView;
//		
//		public function get view():IDetailView
//		{
//			return this._view;
//		}
//		
//		public function set view(value:IDetailView):void {
//			if (StringUtils.isNullOrEmpty(this.id)) {
//				this.id = UIDUtil.createUID();
//			}
//			if (this._view !== value) {
//				if (_view) {
//					_view.removeFieldByKey(this.fieldKey);
//				}
//				this._view = value;
//				if (_view) {
//					_view.addField(this);
//				}
//			}
//		}

		[Inspectable(category="General", enumeration="true,false", defaultValue="false")]
		[Bindable("readOnlyChanged")]
		public function get readOnly():Boolean {
			return this.enabled;
		}
		
		public function set readOnly(value:Boolean):void {
			if (this.enabled == value) {
				this.enabled = !value;
				this.dispatchEvent(new Event("readOnlyChanged"));
			}
		}
			
		override mx_internal function addInstance(instance:RadioButton):void {
			instance.setStyle("disabledColor", 0x000000);
			super.addInstance(instance);
		}
	}
}